var addTwoNumbers = function (l1, l2) {
  // l1 = l1.join('')*1
  // l2 = l2.join('')*1
  // let l3 = l1 + l2
  // l3 = l3 + ''
  // let arr = []
  // for(var i of l3) {
  //   arr.unshift(i*1)
  // }
  // return arr
  let right1 = l1.length - 1
  let right2 = l2.length - 1
  let arr = []
  let flag = 0
  let k
  while (right1 >= 0 || right2 >= 0) {
    k = (l1[right1] ? l1[right1] : 0) + (l2[right2] ? l2[right2] : 0) + flag
    flag = Math.floor(k / 10)
    arr.push(k % 10)
    right1--
    right2--
  }
  if (flag > 0) {
    arr.push(1)
  }
  return arr
};
console.log(addTwoNumbers([9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9]));